package net.mcreator.infinite_storage.procedure;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.JsonToNBT;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Item;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.Container;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.Entity;

import net.mcreator.infinite_storage.ElementsInfiniteStorageMod;

import java.util.function.Supplier;
import java.util.Map;
import java.util.HashMap;

@ElementsInfiniteStorageMod.ModElement.Tag
public class ProcedureSmallBagGuiOpen extends ElementsInfiniteStorageMod.ModElement {
	public ProcedureSmallBagGuiOpen(ElementsInfiniteStorageMod instance) {
		super(instance, 41);
	}
	static Map<String, Object> $_dependencies = new HashMap<>();
	public static void executeProcedure(Map<String, Object> dependencies) {
		if (dependencies.get("entity") == null) {
			return;
		}
		Entity entity = (Entity) dependencies.get("entity");
		String ItemIdTemp = "";
		String NbtTemp = "";
		for (int index0 = 0; index0 < (int) (27); index0++) {
			if ((!(((((entity instanceof EntityLivingBase) ? ((EntityLivingBase) entity).getHeldItemMainhand() : ItemStack.EMPTY).hasTagCompound()
					? ((entity instanceof EntityLivingBase) ? ((EntityLivingBase) entity).getHeldItemMainhand() : ItemStack.EMPTY).getTagCompound()
							.getString("ItemSave")
					: "")).equals("")))) {
				String ItemTempTemp = (((entity instanceof EntityLivingBase) ? ((EntityLivingBase) entity).getHeldItemMainhand() : ItemStack.EMPTY)
						.hasTagCompound()
								? ((entity instanceof EntityLivingBase) ? ((EntityLivingBase) entity).getHeldItemMainhand() : ItemStack.EMPTY)
										.getTagCompound().getString("ItemSave")
								: "");
				String[] ItemTemp = ItemTempTemp.split("_,_");
				ItemIdTemp = (String) ItemTemp[index0];
				String ItemNumTempTextTemp = (((entity instanceof EntityLivingBase)
						? ((EntityLivingBase) entity).getHeldItemMainhand()
						: ItemStack.EMPTY).hasTagCompound()
								? ((entity instanceof EntityLivingBase) ? ((EntityLivingBase) entity).getHeldItemMainhand() : ItemStack.EMPTY)
										.getTagCompound().getString("ItemNumSave")
								: "");
				String[] ItemNumTempArray = ItemNumTempTextTemp.split("_,_");
				int[] ItemNumTemp = new int[ItemNumTempArray.length];
				for (int i = 0; i < ItemNumTempArray.length; i++) {
					ItemNumTemp[i] = Integer.parseInt(ItemNumTempArray[i]);
				}
				int NumTemp = ItemNumTemp[index0];
				String ItemMetaTempTextTemp = (((entity instanceof EntityLivingBase)
						? ((EntityLivingBase) entity).getHeldItemMainhand()
						: ItemStack.EMPTY).hasTagCompound()
								? ((entity instanceof EntityLivingBase) ? ((EntityLivingBase) entity).getHeldItemMainhand() : ItemStack.EMPTY)
										.getTagCompound().getString("ItemMetaSave")
								: "");
				String[] ItemMetaTempArray = ItemMetaTempTextTemp.split("_,_");
				int[] ItemMetaTemp = new int[ItemMetaTempArray.length];
				for (int i = 0; i < ItemMetaTempArray.length; i++) {
					ItemMetaTemp[i] = Integer.parseInt(ItemMetaTempArray[i]);
				}
				int MetaTemp = ItemMetaTemp[index0];
				String ItemNbtTempTemp = (((entity instanceof EntityLivingBase) ? ((EntityLivingBase) entity).getHeldItemMainhand() : ItemStack.EMPTY)
						.hasTagCompound()
								? ((entity instanceof EntityLivingBase) ? ((EntityLivingBase) entity).getHeldItemMainhand() : ItemStack.EMPTY)
										.getTagCompound().getString("ItemNbtSave")
								: "");
				String[] ItemNbtTemp = ItemNbtTempTemp.split("_,_");
				NbtTemp = (String) ItemNbtTemp[index0];
				if ((!(((ItemIdTemp)).equals("minecraft:air")))) {
					if (entity instanceof EntityPlayerMP) {
						Container _current = ((EntityPlayerMP) entity).openContainer;
						if (_current instanceof Supplier) {
							Object invobj = ((Supplier) _current).get();
							if (invobj instanceof Map) {
								ItemStack _setstack = new ItemStack(Item.getByNameOrId((ItemIdTemp)), (int) (1));
								_setstack.setCount((int) NumTemp);
								((Slot) ((Map) invobj).get((int) (index0))).putStack(_setstack);
								_current.detectAndSendChanges();
							}
						}
					}
					if ((MetaTemp != 0)) {
						((new Object() {
							public ItemStack getItemStack(int sltid) {
								if (entity instanceof EntityPlayerMP) {
									Container _current = ((EntityPlayerMP) entity).openContainer;
									if (_current instanceof Supplier) {
										Object invobj = ((Supplier) _current).get();
										if (invobj instanceof Map) {
											return ((Slot) ((Map) invobj).get(sltid)).getStack();
										}
									}
								}
								return ItemStack.EMPTY;
							}
						}.getItemStack((int) (index0)))).setItemDamage((int) MetaTemp);
					}
					if ((!(((NbtTemp)).equals("-1")))) {
						NBTTagCompound itemNbtTag = null;
						try {
							itemNbtTag = JsonToNBT.getTagFromJson((NbtTemp));
						} catch (Exception e) {
							e.printStackTrace();
						}
						{
							ItemStack _stack = (new Object() {
								public ItemStack getItemStack(int sltid) {
									if (entity instanceof EntityPlayerMP) {
										Container _current = ((EntityPlayerMP) entity).openContainer;
										if (_current instanceof Supplier) {
											Object invobj = ((Supplier) _current).get();
											if (invobj instanceof Map) {
												return ((Slot) ((Map) invobj).get(sltid)).getStack();
											}
										}
									}
									return ItemStack.EMPTY;
								}
							}.getItemStack((int) (index0)));
							if (!_stack.hasTagCompound())
								_stack.setTagCompound(new NBTTagCompound());
							_stack.setTagCompound(itemNbtTag);
						}
					}
				}
			} else {
				break;
			}
		}
	}
}
